package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.StoreService;
import com.tarena.lbs.common.basic.converter.StoreConverter;
import com.tarena.lbs.pojo.basic.bo.StoreBO;
import com.tarena.lbs.pojo.basic.dos.StoreDO;
import com.tarena.lbs.pojo.basic.param.StoreParam;
import com.tarena.lbs.pojo.basic.query.AreaStoreQuery;
import com.tarena.lbs.pojo.basic.query.StoreQuery;
import com.tarena.lbs.pojo.basic.vo.StoreVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class StoreController {
    @Autowired
    private StoreService storeService;
    @Autowired
    private StoreConverter storeConverter;

    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> storeList(@RequestBody StoreQuery query) throws BusinessException{
        log.debug("获取商铺的分页信息入参:{}",query);
        BasePageList<StoreBO> boPages = storeService.storeList(query);
        PageResult<StoreVO> resultPages = storeConverter.assemblePageVOS(boPages, query);
        return new Result<>(resultPages);
    }

    //新增门店的数据
    @PostMapping("/admin/basic/store/add")
    public Result<Void> saveStore(@RequestBody StoreParam storeParam) throws BusinessException{
        log.debug("新增商铺信息入参StoreParam:{}",storeParam);
        StoreDO storeDO = storeConverter.storeParamtoDo(storeParam);
        storeService.saveStore(storeDO,storeParam);
        return Result.success();
    }

    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getCitiesStores(@RequestBody AreaStoreQuery query)throws BusinessException{
        log.debug("根据AreaId查询商铺信息 AreaStoreQuery:{}",query);
        BasePageList<StoreBO> storeBOS=storeService.getCitiesStores(query);
        log.debug("根据AreaId查询商铺信息 AreaStoreQuery:{} 出参:{}",query,storeBOS.getList().toString());
        PageResult<StoreVO> storeVOPageResult = storeConverter.assemblePageVOS(storeBOS, query);
        return new Result<>(storeVOPageResult);
    }



}
